package logic

import (
	"context"
	"errors"
	"short-vid-joy/models/mysql"

	"short-vid-joy/shortrpc/internal/svc"
	"short-vid-joy/shortrpc/shortrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DelCommentLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDelCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelCommentLogic {
	return &DelCommentLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DelCommentLogic) DelComment(in *shortrpc.DelCommentRequest) (*shortrpc.DelCommentResponse, error) {
	// todo: add your logic here and delete this line

	var findUser mysql.User

	if err := findUser.FindUserById(mysql.DB, in.UserId); err != nil {
		return nil, errors.New("用户不存在")
	}

	var video mysql.Video

	if err := video.FindVideoById(mysql.DB, in.VideoId); err != nil {
		return nil, errors.New("视频不存在")
	}

	var findComment mysql.Comment

	if err := findComment.FindCommentById(mysql.DB, in.CommentId); err != nil {
		return nil, errors.New("评论不存在")
	}

	if err := findComment.DelComment(mysql.DB, in.CommentId); err != nil {
		return nil, err
	}

	return &shortrpc.DelCommentResponse{}, nil
}
